home *** CD-ROM | disk | FTP | other *** search
- unit HtShopC;
-
- // Original code provided by HREF Tools Corporation, Inc.
- // http://www.href.com
-
- // Amendments (mainly the WebCreditCard1Execute event and
- // TICVerifyTransactionQueuer handling)
- // by P J Hyde, South Pacific Information Services Ltd
- // http://www.spis.co.nz
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- UTPANFRM, ExtCtrls, StdCtrls, TpLabel, Toolbar, WebMail, WebSock,
- DBTables, DB, WdbSorce, UpdateOk, tpAction, WebTypes, WebIniFL, WebLink,
- WdbLink, WdbScan, WdbGrid, ebutton, TpMemo, WebMemo, DBCtrls, Buttons,
- Grids, DBGrids, ComCtrls, tpStatus, TpMenu, WebCCard, webtrans;
-
- type
- TfmShopPanel = class(TutParentForm)
- ToolBar: TtpToolBar;
- WebDataGrid1: TWebDataGrid;
- WebActionOrderList: TWebAction;
- WebActionPostLit: TWebAction;
- WebDataSource1: TWebDataSource;
- DataSource1: TDataSource;
- Table1: TTable;
- Table1PartNo: TFloatField;
- Table1VendorNo: TFloatField;
- Table1Description: TStringField;
- Table1OnHand: TFloatField;
- Table1OnOrder: TFloatField;
- Table1Cost: TCurrencyField;
- Table1ListPrice: TCurrencyField;
- Table1Qty: TSmallintField;
- WebActionMailer: TWebAction;
- tpStatusBar1: TtpStatusBar;
- tpToolButton1: TtpToolButton;
- Label7: TLabel;
- tpDataModule1: TtpDataModule;
- tpComponentPanel2: TtpComponentPanel;
- PageControl1: TPageControl;
- TabSheet1: TTabSheet;
- DBGrid1: TDBGrid;
- DBNavigator1: TDBNavigator;
- tsEConfig: TTabSheet;
- Label4: TLabel;
- Label5: TLabel;
- Label6: TLabel;
- Label8: TLabel;
- Label9: TLabel;
- EditEMailFrom: TEdit;
- EditEMailTo: TEdit;
- EditMailhost: TEdit;
- EditSubject: TEdit;
- EditMailPort: TEdit;
- GroupBox1: TGroupBox;
- GroupBox2: TGroupBox;
- waScrollGrid: TWebAction;
- WebCreditCard1: TWebCreditCard;
- WebactionQueueTransaction: TWebAction;
- ICVerifyTransactionQueuer: TICVerifyTransactionQueuer;
- procedure Table1QtyGetText(Sender: TField; var Text: string;
- DisplayText: Boolean);
- procedure WebActionPostLitExecute(Sender: TObject);
- procedure WebActionOrderListExecute(Sender: TObject);
- procedure WebActionMailerExecute(Sender: TObject);
- procedure tpToolButton1Click(Sender: TObject);
- procedure waScrollGridExecute(Sender: TObject);
- procedure WebCreditCard1Execute(Sender: TObject);
- procedure WebactionQueueTransactionExecute(Sender: TObject);
- private
- { Private declarations }
- procedure getOrderList( sList: TStringList );
- procedure ConfigEMail;
- public
- { Public declarations }
- function Init: Boolean; override;
- end;
-
- var
- fmShopPanel: TfmShopPanel;
-
- implementation
-
- {$R *.DFM}
-
- uses
- WebApp, ucString, whMail, Appmain;
-
- //------------------------------------------------------------------------------
-
- function TfmShopPanel.Init:Boolean;
- begin
- Result:= inherited Init;
- if not result then
- exit;
- //
- with webdatagrid1 do
- if not isUpdated then refresh;
- //
- fmWebMail.webmail.subject:=''; // init so that we know to config later.
- //
- {Other required settings:
- twebdatagrid
- datascanoptions all set to true, except refresh and checkboxes
- buttonsWhere above
- controlsWhere none
-
- twebdatasource
- maxOpenDataSets 1 (no cloning)
- displaySets defined in .ini file
-
- TTable
- add fields using Delphi field editor
- add calculated field called Qty, type integer
- }
- end;
-
- //------------------------------------------------------------------------------
- //------------------------------------------------------------------------------
-
- procedure TfmShopPanel.ConfigEMail;
- begin
- {configure email based on values on form. These are saved to the
- href.ini file by the Restorer component.}
- // e-mail settings -- please change to use your own defaults!
- if EditEMailFrom.text='' then EditEMailFrom.text:='someone@theweb.com';
- if EditEMailTo.text='' then EditEMailTo.text:='info@href.com';
- if EditMailHost.text='' then EditMailHost.text:='mail.href.com';
- if EditMailPort.text='' then EditMailPort.text:='25';
- if EditSubject.text='' then EditSubject.text:='** Shop1 Sale';
- //
- with fmWebMail.webmail do begin
- Sender.EMail:=EditEmailFrom.text;
- MailTo.clear;
- MailTo.add(editEMailTo.text);
- MailHost.hostname:=EditMailhost.text;
- MailHost.port:=StrToIntDef(EditMailport.text,25);
- Subject:=EditSubject.text;
- end;
- end;
-
- { ------------------------------------------------------------------------- }
-
- { To see what webhub is doing with your data, add %=chDebugInfo=% to the
- bottom of the homepage and/or confirm pages. That will display some
- key arrays: webserver.dbFields, webserver.FormLiterals and websession.Literals.
-
- The data entered by the surfer into the webdatagrid is posted to the
- dbFields array. We need to jump in and copy that to the Literals array,
- because dbFields is cleared at the end of the page. Since we don't have
- a real table to post to, we are using the Literals array as temporary
- storage. (Yes, you could add a temporary order table and post Qty there.)
- }
- procedure TfmShopPanel.WebActionPostLitExecute(Sender: TObject);
- var
- a1,a2:string;
- i:integer;
- begin
- //WebDataSource1.Qty@1316=35
- with TWebAction(Sender).WebApp do begin
- for i:=0 to pred(WebServer.dbFields.count) do begin
- SplitString(WebServer.dbFields[i],'=',a1,a2);
- if a2<>'' then
- Literal[a1]:=a2; {post single entry to Literals array}
- end;
- end;
- end;
-
- { ------------------------------------------------------------------------- }
-
- { Illusion central:
- Make the table act multi-surfer by defining the calculated field as equal to
- the current surfer's Literals.}
- procedure TfmShopPanel.Table1QtyGetText(Sender: TField; var Text: string;
- DisplayText: Boolean);
- begin
- Text:=pWebApp.Literal['webdatasource1.Qty@'+
- Sender.DataSet.FieldByName('PartNo').asString];
- end;
-
-
- { ------------------------------------------------------------------------- }
- { ------------------------------------------------------------------------- }
-
- {Fill a stringlist with the current order.
- Loop thru the Literals[] array looking for items with @ which come from the
- data entry session.}
- procedure TfmShopPanel.getOrderList( sList: TStringList );
- var
- a1,a2:string;
- i:integer;
- begin
- slist.clear;
- with pWebApp.WebSession do begin
- for i:=0 to pred(Literals.count) do begin
- a1:=LeftOfEqual(Literals[i]);
- if pos( '@', a1 ) > 0 then begin
- //WebDataSource1.Qty@1316=35
- SplitString(Literals[i],'=',a1,a2); // SplitString is in the ucString unit
- slist.add( 'Qty ' + a2 + ' of Product #' + RightOf( '@', a1 ));
- end;
- end;
- end;
- end;
-
-
- { ------------------------------------------------------------------------- }
-
- {this is one way to echo the current order.}
- procedure TfmShopPanel.WebActionOrderListExecute(Sender: TObject);
- var
- sList:TStringList;
- begin
- sList:=nil;
- try
- sList:=TStringList.create;
- getOrderList(slist);
- //send out the order, with a <BR> at end of each line
- TWebAction(Sender).WebApp.WebOutput.SendStringListBR(slist);
- finally
- slist.free;
- end;
- end;
-
- { ------------------------------------------------------------------------- }
-
- { Prepare and send mail message.}
- procedure TfmShopPanel.WebActionMailerExecute(Sender: TObject);
- var
- sList:TStringList;
- begin
- with TWebAction(Sender).WebApp, fmWebMail.webmail do begin
- if subject='' then
- configEMail;
- //
- Sender.Name:=Literal['CustFullName'];
- // fill in the message (Lines property)
- Lines.clear;
- Lines.add( 'CUSTOMER:' );
- Lines.add( Literal['CustFullName'] );
- Lines.add( Literal['CustCity'] );
- Lines.add( '' );
- Lines.add( 'ORDER:' );
- sList:=nil;
- try
- sList:=TStringList.create;
- getOrderList(slist);
- Lines.AddStrings(slist);
- finally
- slist.free;
- end;
- execute; {send the message}
- end;
- end;
-
- { ------------------------------------------------------------------------- }
-
- { fun with tool buttons...}
-
- procedure TfmShopPanel.tpToolButton1Click(Sender: TObject);
- begin
- with DBGrid1 do
- if DataSource=nil then begin
- DataSource:=DataSource1;
- DbNavigator1.DataSource:=DataSource1;
- end
- else begin
- DataSource:=nil;
- DbNavigator1.DataSource:=nil;
- end
- end;
-
-
-
-
-
- procedure TfmShopPanel.waScrollGridExecute(Sender: TObject);
- var
- a1,a2:string;
- begin
- inherited;
- with TWebAction(Sender).WebApp do begin
- SplitString(Literal['BtnShop'],' ',a1,a2); // e.g. Next Page
- WebDataGrid1.Command:=a1; // e.g. Next
- end;
- end;
-
- procedure TfmShopPanel.WebCreditCard1Execute(Sender: TObject);
- begin
- inherited;
- with WebCreditCard1,WebCreditCard1.WebApp do
- begin
- if CompareText(Command,'CLEAR')=0 then exit;{ No check if clearing }
- if (not Accept) or { Bad CC number/date }
- (Literal['CardHolderName']='') then { Blank name }
- begin
- Literal['CardProblem']:='Yes'; { Flag the problem }
- WebOutput.send('%=Bounce|confirm=%'); { Bounce back to card entry form}
- end else
- Literal['CardProblem']:=''; { Clear any prior flag }
- end;
- end;
-
- procedure TfmShopPanel.WebactionQueueTransactionExecute(Sender: TObject);
- begin
- inherited;
-
- with WebActionQueueTransaction,WebActionQueueTransaction.WebApp,
- ICVerifyTransactionQueuer,ICVerifyTransactionQueuer.TransactionData do
- begin
- if CompareText(Command,'CHECK')<>0 then // not a check...
- begin // must be a full Queue...
- // as the Creditcard component's details are about to
- // be cleared (for security), we'll copy relevant details
- // to some literals
- Literal['_CardNum']:= StripString(WebCreditCard1.CardNumber,' ');
- Literal['_ExpMonth']:=Leftof('/',WebCreditCard1.ExpirationDate);
- Literal['_ExpYear']:= Rightof('/',WebCreditCard1.ExpirationDate);
- end;
-
- // now do the transaction (Check or Queue is the same, in effect)
- TransactionID := IntToStr(Session); // guaranteed unique for THIS surfer
- TransactionAmount :='20.00'; // of course, this should REALLY come from the Webapp
- // via a form literal! This demo just doesn't happen to do pricing...
- CardNumber := Literal['_CardNum'];
- ExpiryMonth := Literal['_ExpMonth'];
- ExpiryYear := Literal['_ExpYear'];
- QueueTransaction;
- Literal['TransStatus'] := StatusMessage+' at '+DateTimeToStr(Age);
- if TransactionStatus in ([tsTimeOut, tsInvalid, tsCancel, tsAccept, tsReject]) then
- DeleteTransaction
- end; { with }
- end;
-
- end.
-